<?php

/**
 * Controller_shops
 * 供应商设置
 * 公司名称 简称 人员 联系电话 用户名 密码
 */

class Controller_shops extends MyApp {

	public function __construct()
	{

		parent::__construct();

		$this->model->file   = YOU::loadModel('file');
	}
	/** 首页 **/
	public function actionIndex()
	{

	}
	//**------------------------------ 供应商设置  ---------------------**//
	/** 供应商设置列表 **/
	public function actionshopslist ()
	{	
		// 分页
//		YOU::loadLib('page', "", '0');
//		$tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_shops`");
//		$count = $tmp['count'];
//		$page_total = ceil($count/PAGE_LIMIT);
//		// 当前页
//		$p = intval($_GET['p']);
//		if ($p == 0){
//			$p  = 1;
//		}
//		if ($p > 1){
//			$start = PAGE_LIMIT * ($p-1);
//		}else{
//			$start = 0;
//		}

		$shops_lists = $this->db->fetchAll("SELECT * FROM `tbl_shops` ORDER BY shops_id DESC ");
		foreach ($shops_lists as $key => $value){
			
			// 提交者
			$shops_lists[$key]['user_name'] = $this->model->user->getNameById($value['user_id']);
		}

//		$page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
//		$page->next_page   = '下一页>';
//		$page->pre_page    = '<上一页';
//		$page->style_path  = "static/page_style";
		// 导出excel
		if($this->get->output == "excel"){

			include_once("lib/phpexcel/PHPExcel.php");
			include_once("lib/phpexcel/PHPExcel/Writer/Excel2007.php");

			// 输出excel
			$objPHPExcel = new PHPExcel();

			// 输出表头
			$a = 0;
			foreach ($record_lists as $key => $value){
				$objPHPExcel->getActiveSheet()->setCellValue($this->letter_ini[$a] . 1, $value['title']);
				$a++;
			}

			// 输出数据 - 从第2行开始
			$i =2;
			foreach ($staffnew_lists as $key => $value){
				$a = 0;
				foreach ($record_lists as $k => $v){
					$objPHPExcel->getActiveSheet()->setCellValue($this->letter_ini[$a] . $i, (string)$value[$v['name']]);
					$a++;
				}
				$i++;
			}

			$objPHPExcel->createSheet();
			$fname = date("YmdHis").".xls";

			//保存excel—2007格式
			//$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
			//$objWriter->save("public/excel/xxx.xlsx");

			//直接输出到浏览器
			$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
			header("Pragma: public");
			header("Expires: 0");
			header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
			header("Content-Type:application/force-download");
			header("Content-Type:application/vnd.ms-execl");
			header("Content-Type:application/octet-stream");
			header("Content-Type:application/download");;
			header("Content-Disposition:attachment;filename={$fname}");
			header("Content-Transfer-Encoding:binary");
			$objWriter->save('php://output');

			exit;
		}


		//$this->tpl->assign("page", $page->show(4, "yahoo"));
		$this->tpl->assign("shops_lists", $shops_lists);
		$this->tpl->display('shops/m.shops.list.tpl.php');

	}
	/** 供应商添加 **/
	public function actionshopsAdd()
	{
		$shops_lists = $this->db->fetchAll("SELECT * FROM `tbl_shops`");

		if ($_POST){

			$shops_com    	    = $this->post->shops_com;
			$shops_rename  		= $this->post->shops_rename;
			$shops_name    	    = $this->post->shops_name;
			$shops_phone    	= $this->post->shops_phone;
			$shops_user  	    = $this->post->shops_user;
			$shops_pwd   	    = $this->post->shops_pwd;			

            if (empty($shops_com)) {
           
            	Helper_Client::location("请填写供应公司名称", "index.php?a=shops.shopsadd");
            }
			if (empty($shops_rename)) {
           
            	Helper_Client::location("请填写供应公司简称", "index.php?a=shops.shopsadd");
            }
			if (empty($shops_name)) {
           
            	Helper_Client::location("请填写人员姓名", "index.php?a=shops.shopsadd");
            }
			if (empty($shops_phone)) {
           
            	Helper_Client::location("请填写联系电话", "index.php?a=shops.shopsadd");
            }

           	if (!preg_match("/^[0-9]*$/", $shops_phone)) {
            	 	Helper_Client::location("联系电话要为真实电话", "index.php?a=shops.shopsadd");
            }

			// 写入数据库
			$info = array(

			"shops_com"            =>$shops_com,
			"shops_rename"         =>$shops_rename,
			"shops_name"           =>$shops_name,			
			"shops_phone"          =>$shops_phone,
			"shops_user"           =>$shops_user,
			"shops_pwd"            =>$shops_pwd,
			"status"                => 1,
			"create_time"           => date("Y-m-d H:i:s"),
			"update_time"           => "0000-00-00 00:00:00",

			);
			$this->db->do_insert("tbl_shops", $info);
            $sid = $this->db->insert_id();
            $infos = array(
                "user_name"           =>$shops_user,
                "user_password"            =>md5($shops_pwd),
                "user_type"             =>"shops",
                "type_id"             =>$sid,
                "status"                => 1,
                "create_time"           => date("Y-m-d H:i:s"),
                "update_time"           => "0000-00-00 00:00:00",

            );
            $this->db->do_insert("tbl_user", $infos);

			// 跳转
			Helper_Client::location("添加成功", "index.php?a=shops.shopslist");
		}

		$this->tpl->assign("shops_lists", $shops_lists);
		$this->tpl->display('shops/shops.add.tpl.php');
	}
	/** 供应商设置修改 **/
	public function actionshopsUpdate()
	{

		$shops_id   = (int)$this->get->shops_id;
		$shops_data = $this->db->fetchROW("SELECT * FROM `tbl_shops` WHERE `shops_id`='{$shops_id}'");

		if (empty($shops_data)){
			Helper_Client::alert("维护部门人员不存在！");
		}

		if ($_POST){

			$shops_com    	    = $this->post->shops_com;
			$shops_rename  		= $this->post->shops_rename;
			$shops_name    	    = $this->post->shops_name;
			$shops_phone    	= $this->post->shops_phone;
			$shops_user  	    = $this->post->shops_user;
			$shops_pwd   	    = $this->post->shops_pwd;

            if (empty($shops_com)) {
           
            	Helper_Client::location("请填写供应公司名称", "index.php?a=shops.shopsadd");
            }
			if (empty($shops_rename)) {
           
            	Helper_Client::location("请填写供应公司简称", "index.php?a=shops.shopsadd");
            }
			if (empty($shops_name)) {
           
            	Helper_Client::location("请填写人员姓名", "index.php?a=shops.shopsadd");
            }
			if (empty($shops_phone)) {
           
            	Helper_Client::location("请填写联系电话", "index.php?a=shops.shopsadd");
            }
           	if (!preg_match("/^[0-9]*$/", $shops_phone)) {
            	Helper_Client::location("联系电话要为真实电话", "index.php?a=shops.shopslist");
            }
			// 写入数据库
			$info = array(

			"shops_com"            =>$shops_com,
			"shops_rename"         =>$shops_rename,
			"shops_name"           =>$shops_name,			
			"shops_phone"          =>$shops_phone,
			"shops_user"           =>$shops_user,
			"shops_pwd"            =>$shops_pwd,
			"status"                => 1,
			"create_time"           => date("Y-m-d H:i:s"),
			"update_time"           => "0000-00-00 00:00:00",

			);
			$this->db->do_update("tbl_shops", $info, "shops_id='{$shops_id}'");

            $info = array(

                "user_name"           =>$shops_user,
                "user_password"            =>md5($shops_pwd),
                "status"                => 1,
                "update_time"            => date("Y-m-d H:i:s"),


            );
            $this->db->do_update("tbl_user", $info, "user_type = 'shops' and type_id='{$shops_id}'");

			// 跳转
			Helper_Client::location("修改成功", "index.php?a=shops.shops	list&shops_id={$shops_id}");
		}

		$this->tpl->assign("shops_data", $shops_data);
		$this->tpl->display('shops/shops.update.tpl.php');
	}
	/** 供应商设置删除 **/
	public function actionshopsDel()
	{
		$shops_id = $this->get->shops_id;
		$this->db->query("DELETE  FROM `tbl_shops` WHERE shops_id='{$shops_id}'");
        $this->db->query("DELETE  FROM `tbl_user` WHERE user_type = 'shops' and type_id='{$shops_id}'");

		// 跳转
		Helper_Client::location("删除成功", "index.php?a=shops.shopslist");
	}
	//**------------------------------- 申购  -------------------------**//
	/** 供应商设置列表 **/
	public function actionPurchaseList ()
	{	
		// 分页
//		YOU::loadLib('page', "", '0');
//		$tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_shop` WHERE user_id={$this->user['user_id']}");
//		$count = $tmp['count'];
//		$page_total = ceil($count/PAGE_LIMIT);
//		// 当前页
//		$p = intval($_GET['p']);
//		if ($p == 0){
//			$p  = 1;
//		}
//		if ($p > 1){
//			$start = PAGE_LIMIT * ($p-1);
//		}else{
//			$start = 0;
//		}

		$shop_lists = $this->db->fetchAll("SELECT * FROM `tbl_shop` WHERE user_id={$this->user['user_id']} ORDER BY shop_id DESC ");

		foreach ($shop_lists as $key => $value){
			// 提交者
			$shop_lists[$key]['user_name'] = $this->model->user->getNameById($value['user_id']);
		}

//		$page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
//		$page->next_page   = '下一页>';
//		$page->pre_page    = '<上一页';
//		$page->style_path  = "static/page_style";
//
//		$this->tpl->assign("page", $page->show(4, "yahoo"));
		$this->tpl->assign("shop_lists", $shop_lists);
		$this->tpl->display('shops/m.purchase.list.tpl.php');

	}
	/** 供应商添加 **/
	public function actionPurchaseAdd()
	{
		$shops_lists = $this->db->fetchAll("SELECT * FROM `tbl_shop`");

		if ($_POST){

			$shop_content  		= $this->post->shop_content;
			$shop_img    	    = $this->post->shop_img;
			$shop_url    		= $this->post->shop_url;


			if (empty($shop_content)) {
           
            	Helper_Client::location("请填写内容", "index.php?a=shops.purchaseadd");
            }       

			// 写入数据库
			$info = array(

			"shop_name"				=>$shop_name,
			"shop_content"			=>$shop_content,
			"shop_img"				=>$shop_img,			
			"shop_url"				=>$shop_url,
			"user_id"				=>$this->user['user_id'],
			"shop_type"				=> 1,
			"status"                => 1,
			"create_time"           => date("Y-m-d H:i:s"),
			"update_time"           => "0000-00-00 00:00:00",

			);
			$this->db->do_insert("tbl_shop", $info);
			$shop_id = $this->db->insert_id();
			// 附件上传

			$file = $this->model->file->upload("shop_file", $shop_id, array( 
"jpg", "png", "gif",));

			if (!empty($file)){
				$info = array(
				"shop_img" 	=> $file['fname'],
				"shop_site" => 'upload/shop_file/'.$file['fname'],
				);

				$this->db->do_update("tbl_shop", $info, "shop_id='{$shop_id}'");
			}


			// 跳转
			Helper_Client::location("添加成功", "index.php?a=shops.purchaseList");
		}

		$this->tpl->assign("shop_lists", $shop_lists);
		$this->tpl->display('shops/m.purchase.add.tpl.php');
	}
	/** 申购修改 **/
	public function actionPurchaseUpdate()
	{

		$shop_id   = (int)$this->get->shop_id;
		$shop_data = $this->db->fetchRow("SELECT * FROM `tbl_shop` WHERE `shop_id`='{$shop_id}'");

		if (empty($shop_data)){
			Helper_Client::alert("请填写报修内容");
		}

		if ($_POST){

			$shop_content  		= $this->post->shop_content;
			$shop_img    	    = $this->post->shop_img;
			$shop_url    		= $this->post->shop_url;

			if (empty($shop_content)) {
           
            	Helper_Client::location("请填写内容", "index.php?a=shops.purchaseadd");
            }

			// 写入数据库
			$info = array(

			"shop_name"				=>$shop_name,
			"shop_content"			=>$shop_content,
			//"shop_img"				=>$shop_img,			
			"shop_url"				=>$shop_url,
			"shop_type"				=> 1,
			"status"                => 1,
			"create_time"           => date("Y-m-d H:i:s"),
			"update_time"           => "0000-00-00 00:00:00",

			);
            //if(empty($info['shop_img']))unset($info['shop_img']);
			$this->db->do_update("tbl_shop", $info, "shop_id='{$shop_id}'");
            $file = $this->model->file->upload("shop_file", $shop_id, array(
                "jpg", "png", "gif",));

            if (!empty($file)){
                $info = array(
                    "shop_img" 	=> $file['fname'],
                    "shop_site" => 'upload/shop_file/'.$file['fname'],
                );

                $this->db->do_update("tbl_shop", $info, "shop_id='{$shop_id}'");
            }

			// 跳转
			Helper_Client::location("修改成功", "index.php?a=shops.purchaseList");
		}

		$this->tpl->assign("shop_data", $shop_data);
		$this->tpl->display('shops/m.purchase.update.tpl.php');
	}
	/** 申报查看 **/
	public function actionPurchaseDetails()
	{

		$shop_id   = (int)$this->get->shop_id;
		$shop_data = $this->db->fetchRow("SELECT * FROM `tbl_shop` WHERE `shop_id`='{$shop_id}'");

		if (empty($shop_data)){
			Helper_Client::alert("申报内容不存在");
		}		

		$this->tpl->assign("shop_data", $shop_data);
		$this->tpl->display('shops/m.purchase.details.tpl.php');
	}
	/** 申购删除 **/
	public function actionPurchaseDel()
	{
		$shop_id = $this->get->shop_id;
		$this->db->query("DELETE  FROM `tbl_shop` WHERE shop_id='{$shop_id}'");

		// 跳转
		Helper_Client::location("删除成功", "index.php?a=shops.purchaselist");
	}
	//**------------------------------------- 派单  --------------------------------**//
	/** 派单列表 **/
	public function actionAssignlist ()
	{	
		// 分页
//		YOU::loadLib('page', "", '0');
//		$tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_shop` WHERE shop_type in('1','2') ");
//		$count = $tmp['count'];
//		$page_total = ceil($count/PAGE_LIMIT);
//		// 当前页
//		$p = intval($_GET['p']);
//		if ($p == 0){
//			$p  = 1;
//		}
//		if ($p > 1){
//			$start = PAGE_LIMIT * ($p-1);
//		}else{
//			$start = 0;
//		}

		$shop_lists = $this->db->fetchAll("SELECT * FROM `tbl_shop` WHERE shop_type in('1','2') ORDER BY shop_type ASC ");
		foreach($shop_lists as $key=>$value){
			// 操作状态
			$shop_lists[$key]['shop_type'] =$this->shop_type[$value['shop_type']];
			// 采购人员
			if(!empty($value['shops_id'])){

				$shops_name	= $this->db->fetchRow("SELECT `shops_name` FROM `tbl_shops` WHERE shops_id = {$value['shops_id']}");
				$shop_lists[$key]['shops_name'] =$shops_name['shops_name'];
				
			}
			// 提交者
			$shop_lists[$key]['user_name'] = $this->model->user->getNameById($value['user_id']);
		}
	
//		$page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
//		$page->next_page   = '下一页>';
//		$page->pre_page    = '<上一页';
//		$page->style_path  = "static/page_style";
//
//		$this->tpl->assign("page", $page->show(4, "yahoo"));
		$this->tpl->assign("shop_lists", $shop_lists);
		$this->tpl->display('shops/m.assign.list.tpl.php');

	}
	/** 报修修改 **/
	public function actionAssignUpdate()
	{
		
		$shop_id		= (int)$this->get->shop_id;
		$shop_data		= $this->db->fetchRow("SELECT * FROM `tbl_shop` WHERE `shop_id`='{$shop_id}'");
		// 采购人员
		$shops_lists	= $this->db->fetchAll("SELECT * FROM `tbl_shops`");

		if (empty($shop_data)){
			Helper_Client::alert("报修内容不存在");
		}

		if ($_POST){
			
			$shops_id  				= $this->post->shops_id;
			$shop_urgent    	    = $this->post->shop_urgent;
			$shop_remark    		= $this->post->shop_remark;
			$assign_time    		= $this->post->assign_time;
	
			// 写入数据库
			$info = array(

			"shops_id"				=>$shops_id,
			"shop_urgent"			=>$shop_urgent,
			"shop_remark"			=>$shop_remark,
			"assign_time"			=>$assign_time,
			"is_show"				=> 2,
			"shop_type"				=> 2,
			"status"                => 1,
			"update_time"           => "0000-00-00 00:00:00",

			);
			$this->db->do_update("tbl_shop", $info, "shop_id='{$shop_id}'");

			// 跳转
			Helper_Client::location("派单成功", "index.php?a=shops.assignlist");
		}

		$this->tpl->assign("shop_data", $shop_data);
		$this->tpl->assign("shops_lists", $shops_lists);
		$this->tpl->display('shops/m.assign.update.tpl.php');
	}
	//**-------------------------------- 采购 ------------------------------**//
	/** 采购列表 **/
	public function actionProcurementList()
	{	
		// 分页
//		YOU::loadLib('page', "", '0');
//		$tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_shop` WHERE shop_type in('2','3') ");
//		$count = $tmp['count'];
//		$page_total = ceil($count/PAGE_LIMIT);
//		// 当前页
//		$p = intval($_GET['p']);
//		if ($p == 0){
//			$p  = 1;
//		}
//		if ($p > 1){
//			$start = PAGE_LIMIT * ($p-1);
//		}else{
//			$start = 0;
//		}

		$shop_lists = $this->db->fetchAll("SELECT * FROM `tbl_shop` WHERE shop_type in('2','3') ORDER BY shop_id DESC ");
		foreach($shop_lists as $key=>$value){
			// 采购人员
			if(!empty($value['shops_id'])){
				
				$shops_name	= $this->db->fetchRow("SELECT `shops_name` FROM `tbl_shops` WHERE shops_id = {$value['shops_id']}");
				$shop_lists[$key]['shops_name'] =$shops_name['shops_name'];			
			}
			// 提交者
			$shop_lists[$key]['user_name'] = $this->model->user->getNameById($value['user_id']);
		}
		
//		$page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
//		$page->next_page   = '下一页>';
//		$page->pre_page    = '<上一页';
//		$page->style_path  = "static/page_style";
//
//		$this->tpl->assign("page", $page->show(4, "yahoo"));
		$this->tpl->assign("shop_lists", $shop_lists);
		$this->tpl->display('shops/m.procurement.list.tpl.php');

	}
	/** 报修录入 **/
	public function actionProcurementUpdate()
	{
		
		$shop_id		= (int)$this->get->shop_id;
		$shop_data		= $this->db->fetchRow("SELECT * FROM `tbl_shop` WHERE `shop_id`='{$shop_id}'");

		if (empty($shop_data)){
			Helper_Client::alert("报修内容不存在");
		}

		if ($_POST){
			
			$shop_report  			= $this->post->shop_report;
			$accomplish_time    	= $this->post->accomplish_time;

			// 写入数据库
			$info = array(

			"shop_report"			=>$shop_report,
			"accomplish_time"		=>$accomplish_time,
			"is_show"				=> 2,
			"shop_type"				=> 3,
			"status"                => 1,
			"update_time"           => "0000-00-00 00:00:00",

			);
			$this->db->do_update("tbl_shop", $info, "shop_id='{$shop_id}'");

			// 跳转
			Helper_Client::location("提交成功", "index.php?a=shops.procurementlist");
		}

		$this->tpl->assign("shop_data", $shop_data);
		$this->tpl->assign("shops_lists", $shops_lists);
		$this->tpl->display('shops/m.procurement.update.tpl.php');
	}
	/** 采购查看 **/
	public function actionProcurementDetails()
	{	
		$shop_id		= (int)$this->get->shop_id;
		$is_show		= (int)$this->get->is_show;
		$shop_data		= $this->db->fetchRow("SELECT * FROM `tbl_shop` WHERE `shop_id`='{$shop_id}'");
		// 采购人员
		$shops_name= $this->db->fetchRow("SELECT * FROM `tbl_shops` WHERE shops_id={$shop_data['shops_id']}");
		$shop_data['shops_name'] = $shops_name['shops_name'];
		if (empty($shop_data)){
			Helper_Client::alert("报修内容不存在");
		}
		// 申请人
		$shop_data['user_name'] = $this->model->user->getNameById($shop_data['user_id']);
		// 结算
		$shop_data['is_show']=$this->is_show[$shop_data['is_show']];
		
		$this->tpl->assign("is_show", $is_show);
		$this->tpl->assign("shop_data", $shop_data);
		$this->tpl->display('shops/m.procurement.details.tpl.php');

	}
	//**---------------------------------- 结算 ----------------------------**//
	/** 结算列表 **/
	public function actionAccountsList()
	{	
		// 分页
//		YOU::loadLib('page', "", '0');
//		$tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_shop` WHERE shop_type='3' ");
//		$count = $tmp['count'];
//		$page_total = ceil($count/PAGE_LIMIT);
//
//		// 当前页
//		$p = intval($_GET['p']);
//		if ($p == 0){
//			$p  = 1;
//		}
//		if ($p > 1){
//			$start = PAGE_LIMIT * ($p-1);
//		}else{
//			$start = 0;
//		}

		$shop_lists = $this->db->fetchAll("SELECT * FROM `tbl_shop` WHERE shop_type='3' ORDER BY shop_id DESC ");
		foreach($shop_lists as $key=>$value){
			// 公司名称
			if(!empty($value['shops_id'])){

				$shops_com	= $this->db->fetchRow("SELECT `shops_com` FROM `tbl_shops` WHERE shops_id = {$value['shops_id']}");
				$shop_lists[$key]['shops_com'] =$shops_com['shops_com'];			
			}
			// 结算
			$shop_lists[$key]['is_show']=$this->is_show[$value['is_show']];
			
		}
	
//		$page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
//		$page->next_page   = '下一页>';
//		$page->pre_page    = '<上一页';
//		$page->style_path  = "static/page_style";
//
//		$this->tpl->assign("page", $page->show(4, "yahoo"));
		$this->tpl->assign("shop_lists", $shop_lists);
		$this->tpl->display('shops/m.accounts.list.tpl.php');

	}
	/** 结算 **/
	public function actionAccountsUpdate()
	{
		
		$shop_id		= (int)$this->get->shop_id;
		$shop_data		= $this->db->fetchRow("SELECT * FROM `tbl_shop` WHERE `shop_id`='{$shop_id}'");

		if (empty($shop_data)){
			Helper_Client::alert("采购内容不存在");
		}

		if ($_POST){
			$is_show  			= $this->post->is_show;	
			
		
			// 写入数据库
			$info = array(

			"is_show"				=>$is_show,
			"shop_type"				=> 3,
			"status"                => 1,
			"update_time"           => "0000-00-00 00:00:00",

			);
			$this->db->do_update("tbl_shop", $info, "shop_id='{$shop_id}'");

			// 跳转
			Helper_Client::location("修改成功", "index.php?a=shops.accountslist");
		}

		$this->tpl->assign("shop_data", $shop_data);
		$this->tpl->display('shops/m.accounts.update.tpl.php');
	}
	//**--------------------------------- 查询 -------------------------**//
	/** 查询 **/
	public function actionDemandList()
	{	
		// 报修人
		$shops_names			= $this->db->fetchAll("SELECT distinct user_id FROM `tbl_shop`");
		
		foreach ($shops_names as $key=>$value){
			// 名字
			$shops_names[$key]['user_name'] = $this->model->user->getNameById($value['user_id']);
			
		}

		// 查询条件
		$shops_name		= $this->get->shops_name;
		$shops_id		= $this->get->shops_id;
		$from			= $this->get->from;
		$to				= $this->get->to;
		$is_show		= $this->get->is_show;

		$where = " ";
		
		if(!empty($shops_name)){
			
			$staff_id = $this->model->user->getIdByName($shops_name);
			// 申报人姓名
			$where .= " AND a.user_id LIKE '{$staff_id}'";
			$this->tpl->assign("shops_name", $shops_name);
		}
		if(!empty($shops_id)){
			// 维修单位
			$where .= " AND a.shops_id = '$shops_id'";
			$this->tpl->assign("shops_id", $shops_id);
		}
		if(!empty($from)){
			// 维修完成开始时间
			$where .= " AND a.accomplish_time >= '$from' ";
			$this->tpl->assign("from", $from);
		}
		if(!empty($to)){
			// 维修完成结束时间
			$where .= " AND a.accomplish_time <= '$to'";
			$this->tpl->assign("to", $to);
		}
		if(!empty($is_show)){
			// 维修完成结束时间
			$where .= " AND a.is_show = '$is_show'";
			$this->tpl->assign("is_show", $is_show);
		}
		// 结算类型
		$is_shows = $this->is_show;
	
		// 采购单位
		$shops_lists		= $this->db->fetchAll("SELECT * FROM `tbl_shops`");
//		// 分页
//		YOU::loadLib('page', "", '0');
//		$tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_shop` AS a,`tbl_shops` AS b  WHERE a.shops_id= b.shops_id AND shop_type='3' {$where}");
//		$count = $tmp['count'];
//		$page_total = ceil($count/PAGE_LIMIT);
//
//		// 当前页
//		$p = intval($_GET['p']);
//		if ($p == 0){
//			$p  = 1;
//		}
//		if ($p > 1){
//			$start = PAGE_LIMIT * ($p-1);
//		}else{
//			$start = 0;
//		}

		$shop_lists = $this->db->fetchAll("SELECT * FROM `tbl_shop` AS a,`tbl_shops` AS b  WHERE a.shops_id= b.shops_id {$where} AND shop_type='3'  ORDER BY a.shop_id DESC ");
	
		foreach($shop_lists as $key=>$value){
			// 公司名称
			if(!empty($value['shops_id'])){

				$shops_com	= $this->db->fetchRow("SELECT `shops_com` FROM `tbl_shops` WHERE shops_id = {$value['shops_id']}");
				$shop_lists[$key]['shops_com'] =$shops_com['shops_com'];			
			}
			// 结算
			$shop_lists[$key]['is_show']=$this->is_show[$value['is_show']];
			// 提交者
			$shop_lists[$key]['user_name'] = $this->model->user->getNameById($value['user_id']);
		}
//
//		$page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
//		$page->next_page   = '下一页>';
//		$page->pre_page    = '<上一页';
//		$page->style_path  = "static/page_style";
//		$this->tpl->assign("page", $page->show(4, "yahoo"));
//
		$this->tpl->assign("is_shows", $is_shows);
		$this->tpl->assign("shop_lists", $shop_lists);
		$this->tpl->assign("shops_lists", $shops_lists);
		$this->tpl->assign("shops_names", $shops_names);

		$this->tpl->display('shops/m.demand.list.tpl.php');

	}
}

?>